import {
  DesktopOutlined,
} from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { Breadcrumb, Layout, Menu } from 'antd';
import React, { useState,useEffect } from 'react';
import {NavLink,Outlet} from "react-router-dom"
import {mainRouter} from "../router/router_config"
const { Header, Content, Footer, Sider } = Layout;
type MenuItem = Required<MenuProps>['items'][number];

const App: React.FC = () => {
  const [collapsed, setCollapsed] = useState(false);
  const [meunList,setMenulist] = useState< MenuItem[]> ([]);
  
  useEffect(()=>{
    let data:MenuItem[] = [] 
    mainRouter.forEach((item,index)=>{
      data.push(getItem(<NavLink to={item.path as string}>{item.title}</NavLink>,index,<DesktopOutlined />))
    })
    setMenulist(data);  
  },[])
  function getItem(
    label: React.ReactNode,
    key: React.Key,
    icon?: React.ReactNode,
    children?: MenuItem[],
  ): MenuItem {
    return {
      key,
      icon,
      children,
      label,
    } as MenuItem;
  }
  
  return (
    <Layout style={{ minHeight: '100vh' }}>
      <Sider theme='light' collapsible collapsed={collapsed} onCollapse={value => setCollapsed(value)}>
        <div className="logo" />
        <Menu theme="light" defaultSelectedKeys={['1']} mode="inline" items={meunList} />
      </Sider>
      <Layout className="site-layout">
        <Header className="site-layout-background" style={{ padding: 0 }} />
        <Content style={{ margin: '0 16px' }}>
         
          <div className="site-layout-background" style={{ height:"100%",width:"100%", padding: 24, minHeight: 360 }}>
            <Outlet/>
          </div>
        </Content>
        <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
      </Layout>
    </Layout>
  );
};

export default App;